<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pvsbufread</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pvsbuffer.html" title="pvsbuffer" />
    <link rel="next" href="pvsbufread2.html" title="pvsbufread2" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pvsbufread</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pvsbuffer.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pvsbufread2.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pvsbufread"></a>
      <div class="titlepage"></div>
      <a id="Indexpvsbufread" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pvsbufread</span>
        </h2>
        <p>pvsbufread — 
      This opcode reads a circular buffer of f-signals (streaming PV signals).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp137955440"></a>
        <h2>Description</h2>
        <p>
      This opcode reads from a circular buffer of length ilen (secs),
      taking a handle for the buffer and a time pointer, which holds the
      current read position (also in seconds). It is used in conjunction with a
      <span class="emphasis"><em>pvsbuffer</em></span> opocde. 
      Reading is circular, wrapping around at the end of the buffer.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138016800"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">fsig <span class="command"><strong>pvsbufread</strong></span>  ktime, khandle[, ilo, ihi, iclear] </pre>
      </div>
      <div class="refsect1">
        <a id="idp138018960"></a>
        <h2>Initialisation</h2>
        <p>
      <span class="emphasis"><em>ilo, ihi</em></span> -- set the lowest and highest freqs to be read from the buffer (defaults to 0, Nyquist).
    </p>
        <p>
      <span class="emphasis"><em>iclear</em></span> -- set to 1 to clear output fsig before every write (default 1), 0 tells the opcode not to clear
      the output fsig. This is relevant when writing to subsets of an fsig frame using <span class="emphasis"><em>ilo</em></span>, <span class="emphasis"><em>ihi</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138022480"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>fsig</em></span> -- output pv stream
    </p>
        <p>
      <span class="emphasis"><em>ktime</em></span> -- time position of reading pointer (in secs).
    </p>
        <p>
      <span class="emphasis"><em>khandle</em></span> -- handle identifying the buffer to be read. When using k-rate
      handles, it is important to initialise the k-rate variable to a given existing handle. When changing
      buffers, fsig buffers need to be compatible (same fsig format).
    </p>
        <p>
      With this opcode and <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>, it is possible to, among other things:
      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">time-stretch/compress a fsig stream, by reading it at
        different rates</li>
            <li class="listitem">delay a fsig or portions of it.</li>
            <li class="listitem">'brassage' two or more fsigs by switching buffers, since
        the reading handles are k-rate. Note that, when using k-rate
        handles, it is important to initialise the k-rate variable to a
        given handle (so that the fsig initialisation can take place)
        and it is only possible to switch handles between compatible
        fsig buffers (with the same fftsize and overlap).</li>
          </ul>
        </div>
        <p>
  </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>It is important that the handle value passed to <span class="emphasis"><em>pvsbufread</em></span> is valid and was created by <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>. Csound will crash with invalid handles.
    </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp138032240"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the pvsbufread opcode. It does 'brassage' by switching between two buffers.
      </p>
        <div class="example">
          <a id="idp138033296"></a>
          <p class="title">
            <strong>Example 677. Example of the pvsbufread opcode</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
fsig1       <span class="opc">pvsanal</span>     asig1, 1024, 256, 1024, 1
fsig2       <span class="opc">pvsanal</span>     asig2, 1024, 256, 1024, 1


ibuf1, kt1  <span class="opc">pvsbuffer</span>   fsig1, 10   <span class="comment">; 10-sec buf with fsig1</span>
ibuf2, kt2  <span class="opc">pvsbuffer</span>   fsig2, 7    <span class="comment">; 7-sec buf with fsig2</span>

khan        <span class="opc">init</span>        ibuf1       <span class="comment">; initialise handle to buf1</span>

<span class="opc">if</span>  ktrig  <span class="op">&gt;</span> 0 <span class="opc">then</span>                 <span class="comment">; switch buffers according to trigger</span>
khan <span class="op">=</span> ibuf2
<span class="opc">else</span>
khan <span class="op">=</span> ibuf1
<span class="opc">endif</span>

fsb         <span class="opc">pvsbufread</span>  kt1, khan   <span class="comment">; read buffer</span></pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>
      Here is an example of the pvsbufread opcode. It uses the file <a class="ulink" href="examples/pvsbufread.csd" target="_top"><em class="citetitle">pvsbufread.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp138050784"></a>
          <p class="title">
            <strong>Example 678. Example of the pvsbufread opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac    <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pvsbufread.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 16
<span class="ohdr">nchnls</span> <span class="op">=</span> 1
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="comment">;; example written by joachim heintz 2009</span>

<span class="oblock">opcode</span> FileToPvsBuf, iik, Siiii
<span class="comment">;;writes an audio file at the first k-cycle to a fft-buffer (via pvsbuffer)</span>
Sfile, ifftsize, ioverlap, iwinsize, iwinshape <span class="opc">xin</span>
ktimek		<span class="opc">timeinstk</span>
<span class="octrl">if</span> ktimek <span class="op">==</span> 1 then
ilen		<span class="opc">filelen</span>	Sfile
kcycles	<span class="op">=</span>		ilen <span class="op">*</span> <span class="ohdr">kr</span><span class="comment">; number of k-cycles to write the fft-buffer</span>
kcount		<span class="opc">init</span>		0
<span class="olabel">loop</span><span class="op">:</span>
ain		<span class="opc">soundin</span>	Sfile
fftin		<span class="opc">pvsanal</span>	ain, ifftsize, ioverlap, iwinsize, iwinshape
ibuf, ktim	<span class="opc">pvsbuffer</span>	fftin, ilen <span class="op">+</span> (ifftsize <span class="op">/</span> sr)
		<span class="octrl">loop_lt</span>	kcount, 1, kcycles, <span class="olabel">loop</span>
		<span class="opc">xout</span>		ibuf, ilen, ktim
<span class="octrl">endif</span>
<span class="oblock">endop</span>


<span class="oblock">instr</span> 1
ifftsize	<span class="op">=</span>		1024
ioverlap	<span class="op">=</span>		ifftsize <span class="op">/</span> 4
iwinsize	<span class="op">=</span>		ifftsize
iwinshape	<span class="op">=</span>		1<span class="comment">; von-Hann window</span>
ibuffer, ilen, k0		FileToPvsBuf	"fox.wav", ifftsize, ioverlap, iwinsize, iwinshape
ktmpnt		<span class="opc">linseg</span>		ilen, p3, 0<span class="comment">; reads the buffer backwards in p3 seconds</span>
fread 		<span class="opc">pvsbufread</span>  	ktmpnt, ibuffer
aout		<span class="opc">pvsynth</span>	fread
		<span class="opc">out</span>		aout
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 5
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138055072"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="pvsanal.html" title="pvsanal"><em class="citetitle">pvsanal</em></a>,
      <a class="link" href="pvsynth.html" title="pvsynth"><em class="citetitle">pvsynth</em></a>,
      <a class="link" href="pvsbuffer.html" title="pvsbuffer"><em class="citetitle">pvsbuffer</em></a>,
      <a class="link" href="pvsadsyn.html" title="pvsadsyn"><em class="citetitle">pvsadsyn</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp138060000"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Victor Lazzarini</td>
          </tr>
          <tr>
            <td>July 2007</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pvsbuffer.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pvsbufread2.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pvsbuffer </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pvsbufread2</td>
        </tr>
      </table>
    </div>
  </body>
</html>
